<template>
	<view class="recharge">
		<u-navbar title="充值"></u-navbar>
		<view class="top_money">
			账户钻石：<image style="width: 40rpx;height: 40rpx;"  mode=""></image>
			<text>{{userInfo.money}}</text>
		</view>
		<view class="center_body">
			<view class="money_list">
				<view @click="moneySelect(moneyList[index].rmb)"
					:class="MonetType == item.id?'money_item item_active':'money_item'"
					v-for="(item,index) in moneyList" :key="index">
					<view class="item_top">
						<image src="../../static/zs.png" mode=""></image>
						<text>{{item.money}}</text>
					</view>
					<view class="item_bottom">
						￥{{item.rmb}}
					</view>
				</view>
			</view>
		</view>
		<view class="pay_type">
			<radio-group @change="changeRadio">
				<view class="pay_type_list_item" v-for="(item,index) in moneyTypeList" :key="index">
					<view class="item_left">
						<view class="icon">
							<cimage :src="item.icon"></cimage>
						</view>
						<text>{{item.name}}</text>
					</view>

					<radio :checked="moneyType===item.id" style="transform:scale(0.9)" color="#00edff"
						:value="item.id" />
				</view>
			</radio-group>
			<view class="submit" @click="submit()">
				提交充值
			</view>
		</view>
		<view class="bottom">
			<view class="b_title">
				温馨提示：
			</view>
			<view class="b_text">
				<text>1、充值的余额可用于开盲盒和在发货时支付运费</text>
				<text>2、充值的余额不会过期，支付后的剩余余额不支持赠送不支持提现</text>
				<text>3、未成年人消费需事先取得家人或法定监护人的陪同及监管下进行消费;</text>
				<text>4、充值前请您仔细阅读《支付服务协议》，成功充值即代表您对本协议无异议。</text>
			</view>
			<view class="protocol">
				<u-checkbox-group>
					<u-checkbox v-model="protocol" activeColor="#00edff" shape="circle" label="明月">我已满18岁，已阅读并同意<text
							@click.stop="$.to('/pages/my/agreement?type=wfashuiming')">《支付服务协议》</text></u-checkbox>
				</u-checkbox-group>

			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				MonetType: '',
				noClick: true,
				userInfo: {
					money: '0.00',
				},
				protocol: true,
				// 充值金额
				money: '',
				// 哪种支付方式
				moneyType: '0',
				// 可选金额
				moneyList: [
					// {money:10,type:0},
					// {money:50,type:0},
					// {money:100,type:0},
					// {money:200,type:0},
					// {money:300,type:0},
					// {money:500,type:0},

				],
				// 支付方式
				moneyTypeList: [{
						icon: '/static/icon/wei_xin.png',
						name: '微信支付',
						id: '0',
						type: 'wechat'
					},
					// //#ifndef MP-WEIXIN
					// {icon:'../../../static/image/zhifubao.png',name:'支付宝支付',id:'1',type:'alipay'},
					// //#endif
				]
			}
		},
		onLoad() {
			this.getRechargeList()
		},
		onShow() {
			this.$store.dispatch('getUserInfo').then(res => {
				console.log(res);
				this.userInfo = res.data
			})
		},
		methods: {
			getRechargeList() {
				this.req({
					url: '/v1/user/recharge',
					success: res => {
						console.log(res);
						if (res.code == 200) {
							this.moneyList = res.data.data
						}
					}
				})
			},
			moneySelect(val) {
				this.moneyList.forEach(item => {
					if (Number(item.rmb) == val) {
						this.MonetType = item.id
						this.money = item.rmb
					}
				})
			},
			inputValue(e) {
				this.money = e.detail.value
				this.moneySelect(this.money)
			},
			changeRadio(e) {
				this.moneyType = e.detail.value
			},
			getPage() {
				console.log(222);
			},
			submit() {
				if (!this.protocol){
					this.$common.toast({
					  title: '请阅读并同意支付服务协议'
					})
					return
				}
				if (!this.money || this.money < 0){
					this.$common.toast({
					  title: '请选择正确金额'
					})
					return
				}
				if (!this.moneyTypeList[0]) {
					this.$common.toast({
					  title: '请选择正确的支付方式'
					})
					return
				}
				let id = 0
				this.moneyList.forEach(item => {
					if (item.rmb === this.money) {
						id = item.id
					}
				})
				this.req({
					url: '/v1/user/recharge/gopay',
					data:{
						id,
					},
					success: res => {
						console.log(res);
						if(res.msg == '充值成功!'){
							this.$common.toast({
							  title: '充值成功'
							})
							this.$store.dispatch('getUserInfo').then(res => {
								console.log(res);
								this.userInfo = res.data
							})
							return
						}
						this.$common.orderPay(res.data).then(res1 => {
							console.log(res1);
						  if (res1 == 'success') {
							  console.log();
						  }
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.recharge {

		.top_money {
			padding: 20rpx;
			font-size: 32rpx;

			image {
				vertical-align: bottom;
			}

			text {
				font-size: 30rpx;
				padding-left: 6rpx;
			}
		}

		.center_body {
			margin-top: 40rpx;
			padding: 20rpx;
			border-top: 1px solid #eeeeee;
			border-bottom: 1px solid #eeeeee;

			.money_list {
				padding-top: 20rpx;
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;
				justify-content: flex-start;

				.item_active {
					background: #ff9d00 !important;
					color: #fff;
				}

				.money_item {
					width: calc(33.33% - 20rpx);
					// height: 120rpx;
					padding: 25rpx 0;
					background: #f0f0f0;
					margin: 0 10rpx;
					margin-bottom: 40rpx;
					border-radius: 10rpx;
					display: flex;
					flex-direction: column;
					text-align: center;

					.item_top {

						text {
							font-weight: bold;
							padding-left: 6rpx;
						}

						image {
							width: 40rpx;
							height: 40rpx;
							vertical-align: bottom;
						}
					}

					.item_bottom {
						margin-top: 8rpx;
					}
				}
			}

			.zdy_money {
				display: flex;
				align-items: center;
				margin-top: 40rpx;

				text {
					font-size: 32rpx;
					font-weight: bold;
				}

				input {
					margin-left: 20rpx;
					font-size: 30rpx;
					flex: 1;
				}
			}
		}

		.pay_type {
			.submit {
				width: 90%;
				padding: 20rpx 0;
				text-align: center;
				border-radius: 10rpx;
				background: #ff9d00;
				font-size: 32rpx;
				color: #fff;
				margin: 0rpx auto;
				margin-top: 60rpx;
			}

			.pay_type_list_item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin: 30rpx 20rpx;
				.item_left {
					display: flex;
					height: 55rpx;
					.icon{
						width: 55rpx !important;
						height: 55rpx;
						vertical-align: bottom;
					}
					text {
						font-size: 32rpx;
						margin-left: 10rpx;
					}
				}

				radio {
					// width: 20rpx;
					// height: 20rpx;
				}
			}
		}

		.bottom {

			padding: 20rpx;

			.b_title {
				font-size: 32rpx;
				font-weight: bold;
				color: #747474;
			}

			.b_text {
				color: #9c9c9c;
				font-size: 24rpx;
				display: flex;
				flex-direction: column;
			}

			.protocol {
				margin-top: 40rpx;
				text-align: center;
				display: flex;
				justify-content: center;
				// text{
				// 	margin-left: -30rpx;
				// }
			}
		}
	}
</style>